package com.qubuyer.business.home.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter

/**
 * @author Susong
 * @date 创建时间2019/3/9
 * @description 首页分类PagerAdapter
 * @version
 */
class HomeViewPagerAdapter(val pageList: List<View>) : PagerAdapter() {

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val pageView = pageList[position]
        if (container.indexOfChild(pageView) != -1) {
            return pageView
        }
        container.addView(pageView)
        return pageView
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(`object` as View)
    }

    override fun getCount(): Int {
        return pageList.size
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view === `object`
    }
}